package map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

//foreach遍历集合 基于lambda
public class ForEachDemo {
    public static void main(String[] args) {
        Map<String,Integer> map=new HashMap<>();
        map.put("数学",77);
        map.put("英语",90);
        map.put("物理",89);
        map.put("化学",78);
        System.out.println(map);
        Set<String>keySet=map.keySet();
        keySet.forEach(new Consumer<String>() {
            @Override
            public void accept(String k) {
                System.out.println(k);

            }
        });
        keySet.forEach(k-> System.out.println("key:"+k));

        Collection<Integer>values=map.values();
        values.forEach(v-> System.out.println("value:"+v));


        Set<Map.Entry<String,Integer>> entrySet=map.entrySet();
        entrySet.forEach(e-> System.out.println("key:"+e.getKey()+" value:"+e.getValue()));
        System.out.println("--------------------------------------");

        map.forEach((k,v)-> System.out.println("key:"+k));
        map.forEach((k,v)-> System.out.println("value:"+v));
        map.forEach((k,v)-> System.out.println("key:"+k+"value"+v));




    }
}
